import { OSSModule } from '@nest-public/nest-oss';
import { MiddlewareConsumer, Module, RequestMethod, Logger } from '@nestjs/common';
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
import { CommentModule } from 'lib/comment/comment.module';
import { User } from './../../../libs/db/src/entity/user.entity';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AreaModule } from './area/area.module';
import { AssetsTypeModule } from './assets-type/assets-type.module';
import { AssetsModule } from './assets/assets.module';
import { FeedbackModule } from './feedback/feedback.module';
import { FundsModule } from './funds/funds.module';
import { GroupModule } from './group/group.module';
import { LearningResourcesModule } from './learning-resources/learning-resources.module';
import { MigrateModule } from './migrate/migrate.module';
import { NonOperatingAssetsModule } from './non-operating-assets/non-operating-assets.module';
import { OperatingAssetsModule } from './operating-assets/operating-assets.module';
import { OrgActionTypeModule } from './org-action-type/org-action-type.module';
import { OrgActionModule } from './org-action/org-action.module';
import { PartyMemberModule } from './party-member/party-member.module';
import { PhotoMetadataModule } from './photo-metadata/photo-metadata.module';
import { PhotoModule } from './photo/photo.module';
import { ProjectConstructionModule } from './project-construction/project-construction.module';
import { ResourcesTypeModule } from './resources-type/resources-type.module';
import { ResourcesModule } from './resources/resources.module';
import { SubsidyInfoModule } from './subsidy-info/subsidy-info.module';
import { SubsidyTypeModule } from './subsidy-type/subsidy-type.module';
import { SubsidyModule } from './subsidy/subsidy.module';
import { TownModule } from './town/town.module';
import { UserModule } from './user/user.module';
import { VillageActionTypeModule } from './village-action-type/village-action-type.module';
import { VillageActionModule } from './village-action/village-action.module';
import { VillageBulletinBoardModule } from './village-bulletin-board/village-bulletin-board.module';
import { VillageCadreModule } from './village-cadre/village-cadre.module';
import { VillageMeetingModule } from './village-meeting/village-meeting.module';
import { VillageModule } from './village/village.module';
import { VillagerModule } from './villager/Villager.module';
import { LoggerMiddleware } from './_middleware/logger.middleware';
import { LoggerModule } from './_logger/logger.module';


const config = {
  client: {
    region: process.env.REGION,
    accessKeyId: process.env.ACCESSKEY_ID,
    accessKeySecret: process.env.ACCESSKEY_SECRET,
    bucket: process.env.BUCKET,
    internal: false, // 是否使用阿里云内部网访问
    secure: true, // 使用 HTTPS
    cname: false, // 自定义endpoint
    timeout: '90s'
  },
  domain: '', // 自定义域名
};


@Module({
  imports: [
    LoggerModule,

    CommentModule,

    AreaModule,
    AssetsModule,
    AssetsTypeModule,
    FeedbackModule,
    FundsModule,
    GroupModule,
    LearningResourcesModule,
    MigrateModule,
    NonOperatingAssetsModule,
    OperatingAssetsModule,
    OrgActionModule,
    OrgActionTypeModule,
    PartyMemberModule,
    PhotoMetadataModule,
    ProjectConstructionModule,
    ResourcesModule,
    ResourcesTypeModule,
    SubsidyModule,
    SubsidyInfoModule,
    SubsidyTypeModule,
    TownModule,
    UserModule,
    VillageModule,
    VillageActionModule,
    VillageActionTypeModule,
    VillageBulletinBoardModule,
    VillageCadreModule,
    VillageMeetingModule,
    VillageModule,
    VillagerModule,
    PhotoModule,
    PhotoMetadataModule,

    OSSModule.forRoot(config),

    TypeOrmModule.forFeature([User]),
  ],
  controllers: [
    AppController
  ],
  providers: [AppService],
})
export class AppModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(LoggerMiddleware)
      .forRoutes({
        path: '*',
        method: RequestMethod.ALL
      });
  }
}
